﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightMenu.Library;

namespace SilverlightMenu
{
    public partial class MainPage : UserControl
    {
        int menuIndex = 1;
        public MainPage()
        {
            InitializeComponent();
        }

        private void Menu_MenuItemClicked(object sender, EventArgs e)
        {
            var clickedItem = (MenuItem)sender;

            if (clickedItem.IsCheckable)
                MessageBox.Show(string.Format("{0} is now {1}", clickedItem.Name, clickedItem.IsChecked ? "CHECKED" : "UNCHECKED"));
            else
                MessageBox.Show(string.Format("You clicked: {0}", clickedItem.Name));

            switch (clickedItem.Name)
            {
                case "mnuOpenProject":
                    var newMenuItem = new MenuItem()
                    {
                        Name = string.Format("Item{0}", menuIndex),
                        Text = string.Format("{0} Item {0}", menuIndex)
                    };
                    menuIndex++;
                    mnuTop.AddMenuItem(clickedItem, newMenuItem);
                    break;
            }
        }
    }
}
